﻿@using System.Web.UI.WebControls
@using CQIE.TES.Model

@{
    Layout = "~/Views/Shared/Template.cshtml";
    Question leaderQuestion = ViewBag.LeaderQuestion;
    Question DepartmentQuestion = ViewBag.DepartmentQuestion;
}

@functions
{

    public string GetChild(Question model)
    {

        if (model.Children.Count != 0)
        {
            List<string> s = new List<string>();
            s.Add($"<div class=\"typeArray\"><h1>{model.Info}</h1>");
            for (int i = 0; i < model.Children.Count; i++)
            {
                s.Add(GetChild(model.Children.ToList()[i]));
            }
            s.Add("</div>");
            string myhtml = "";
            foreach (string item in s)
            {
                myhtml += item;
            }
            return myhtml;
        }
        else
        {
            return $"<p>{model.Info}</p>" +
                       $"<input class='layui-input' type='Text' name={model.ID} value='{model.Height*100}'>" +
                       $"<hr/>";
        }
    }

}

<style>
    .layui-tab-item {
        padding: 0 30px;
       
    }
   
    p{
        width:134px;
        display:inline-block;
    }
    .tle {
        width: 608px;
        display: inline-block;
        height: 28px;
        line-height: 28px;
        margin: 24px 28px;
        
    }
    .typeArray {
        border: 1px solid red;
        margin: 10px;
        padding: 10px;

    }

        .typeArray .typeArray {
            border: 1px solid blue;
            padding: 10px;
        }
</style>

<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">学生评教问卷</li>
        <li>教研室领导问卷</li>
        <li>系部评教问卷</li>
        <li>教师互评问卷</li>
        <li>教师自评问卷</li>
    </ul>
    <div class="layui-tab-content" style="height: 100px;">
        <div class="layui-tab-item layui-show">
            <form id="student" lay-filter="studentForm" class="layui-form">
                @foreach (Question studentQuestion in ViewBag.StudentQuestions)
                {
                    <div class="tle">
                        <p>@studentQuestion.Info</p>
                        @Html.TextBox(studentQuestion.ID.ToString(), studentQuestion.Height * 100,
                            new { @class = "layui-input" })
                        
                    </div>
                }
            <button lay-filter="student" lay-submit class="layui-btn layui-btn-normal">保存</button>
            </form>
        </div>

        <div class="layui-tab-item">
            <form id="teachingOffice" lay-filter="teachingOfficeForm" class="layui-form">
                @Html.Raw(GetChild(leaderQuestion))
                <button lay-filter="teachingOffice" lay-submit class="layui-btn layui-btn-normal">保存</button>
            </form>
        </div>

        <div class="layui-tab-item">
            <form id="department" lay-filter="departmentForm" class="layui-form">
                @Html.Raw(GetChild(DepartmentQuestion))
                <button lay-filter="department" lay-submit class="layui-btn layui-btn-normal">保存</button>
            </form>
            
        </div>

        <div class="layui-tab-item">
            <form id="teacher" lay-filter="teacherForm" class="layui-form">
                @foreach (Question teacherQuestion in ViewBag.TeacherQuestion)
                {
                    <div class="tle">
                        <p>@teacherQuestion.Info</p>
                        @Html.TextBox(teacherQuestion.ID.ToString(), teacherQuestion.Height * 100, 
                            new { @class = "layui-input" })
                    </div>
                }
                <button lay-filter="teacher" lay-submit class="layui-btn layui-btn-normal">保存</button>
            </form>
        </div>

        <div class="layui-tab-item">
            <form id="self" lay-filter="selfForm" class="layui-form">
                @foreach (Question selfQuestion in ViewBag.SelfQuestions)
                {
                    <div class="tle">
                        <p>@selfQuestion.Info</p>
                        @Html.TextBox(selfQuestion.ID.ToString(), selfQuestion.Height * 100, 
                            new{@class= "layui-input" })
                        
                    </div>
                }
                <button lay-filter="self" lay-submit class="layui-btn layui-btn-normal">保存</button>
            </form>
        </div>
    </div>
</div>

<script>
    //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
    layui.use(['element','form','jquery'], function(){
        var element = layui.element;
        var form = layui.form;
        var $ = layui.jquery;

        /**
         * 将layui中获取到的form值转为两个数组 keys、values
         * object data
         */
        function getParams(data) {
            let k = Object.keys(data);
            let v = Object.values(data);
            let res = {
                mode : 1,
                questions: k,
                height: v
            };
            return res;
        }

        form.on('submit(student)', function() {
            let data = form.val("studentForm");
            // 
            let params = getParams(data);
            $.post("/api/question/saveheight",
                params,
                function(res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 2 });
                    }
                });

            return false;
        });

        form.on('submit(teachingOffice)', function () {
            let data = form.val("teachingOfficeForm");
            // 
            let params = getParams(data);
            $.post("/api/question/saveheight",
                params,
                function (res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 2 });
                    }
                });

            return false;
        });

        form.on('submit(department)', function () {
            let data = form.val("departmentForm");
            // 
            let params = getParams(data);
            $.post("/api/question/saveheight",
                params,
                function (res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 2 });
                    }
                });

            return false;
        });

        form.on('submit(teacher)', function () {
            let data = form.val("teacherForm");
            // 
            let params = getParams(data);
            $.post("/api/question/saveheight",
                params,
                function (res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 2 });
                    }
                });

            return false;
        });

        form.on('submit(student)', function () {
            let data = form.val("studentForm");
            // 
            let params = getParams(data);
            $.post("/api/question/saveheight",
                params,
                function (res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 2 });
                    }
                });

            return false;
        });

        form.on('submit(self)', function () {
            let data = form.val("selfForm");
            // 
            let params = getParams(data);
            $.post("/api/question/saveheight",
                params,
                function (res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 2 });
                    }
                });

            return false;
        });

    });
</script>